#include<stdio.h>
typedef struct student{
	int num;
	char name[20];
	int score;
	char grade;
}STU,*STUDENT; 
int grade(STUDENT st,int n){
	int count=0;
	for(int i=0;i<n;i++){
		if(st->score<60){
			st->grade='D';
			count++;
		}
		else if(st->score>=60&&st->score<=69){
			st->grade='C';
		}
		else if(st->score>=70&&st->score<=84){
			st->grade='B';
		}
		else{
			st->grade='A';
		}
		st++;
	}
	return count;
}
int main(){
	STU st[100];
	STUDENT p;
	p=st;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %s %d",&st[i].num,&st[i].name,&st[i].score);
	}
	printf("%d\n",grade(st,n));
	for(int i=0;i<n;i++){
		printf("%d %s %c\n",st[i].num,st[i].name,st[i].grade);
	}
	return 0;
}
